from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-03-25 14:02:25.285414
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 25, Mar, 2022
Time: 14:02:30
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.6812
Nobs: 606.000 HQIC: -49.0810
Log likelihood: 7299.81 FPE: 3.74814e-22
AIC: -49.3356 Det(Omega_mle): 3.23477e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.348321 0.066338 5.251 0.000
L1.Burgenland 0.107534 0.040429 2.660 0.008
L1.Kärnten -0.110662 0.021150 -5.232 0.000
L1.Niederösterreich 0.192881 0.084503 2.283 0.022
L1.Oberösterreich 0.120051 0.083316 1.441 0.150
L1.Salzburg 0.259543 0.042890 6.051 0.000
L1.Steiermark 0.037668 0.056614 0.665 0.506
L1.Tirol 0.103085 0.045682 2.257 0.024
L1.Vorarlberg -0.068180 0.040339 -1.690 0.091
L1.Wien 0.016954 0.074156 0.229 0.819
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.053486 0.142477 0.375 0.707
L1.Burgenland -0.038474 0.086832 -0.443 0.658
L1.Kärnten 0.042056 0.045424 0.926 0.355
L1.Niederösterreich -0.202015 0.181492 -1.113 0.266
L1.Oberösterreich 0.454406 0.178942 2.539 0.011
L1.Salzburg 0.283028 0.092116 3.073 0.002
L1.Steiermark 0.112666 0.121594 0.927 0.354
L1.Tirol 0.306043 0.098114 3.119 0.002
L1.Vorarlberg 0.026666 0.086638 0.308 0.758
L1.Wien -0.029031 0.159268 -0.182 0.855
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197547 0.033915 5.825 0.000
L1.Burgenland 0.089135 0.020669 4.312 0.000
L1.Kärnten -0.007151 0.010813 -0.661 0.508
L1.Niederösterreich 0.242435 0.043202 5.612 0.000
L1.Oberösterreich 0.159789 0.042595 3.751 0.000
L1.Salzburg 0.040234 0.021927 1.835 0.067
L1.Steiermark 0.027280 0.028944 0.943 0.346
L1.Tirol 0.082091 0.023355 3.515 0.000
L1.Vorarlberg 0.054195 0.020623 2.628 0.009
L1.Wien 0.116488 0.037912 3.073 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.117140 0.033912 3.454 0.001
L1.Burgenland 0.043137 0.020667 2.087 0.037
L1.Kärnten -0.012949 0.010812 -1.198 0.231
L1.Niederösterreich 0.172241 0.043197 3.987 0.000
L1.Oberösterreich 0.335068 0.042591 7.867 0.000
L1.Salzburg 0.100146 0.021925 4.568 0.000
L1.Steiermark 0.112605 0.028941 3.891 0.000
L1.Tirol 0.089629 0.023352 3.838 0.000
L1.Vorarlberg 0.060532 0.020621 2.935 0.003
L1.Wien -0.017858 0.037908 -0.471 0.638
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.124688 0.063592 1.961 0.050
L1.Burgenland -0.044707 0.038756 -1.154 0.249
L1.Kärnten -0.045301 0.020274 -2.234 0.025
L1.Niederösterreich 0.137400 0.081005 1.696 0.090
L1.Oberösterreich 0.160357 0.079867 2.008 0.045
L1.Salzburg 0.284920 0.041114 6.930 0.000
L1.Steiermark 0.058664 0.054271 1.081 0.280
L1.Tirol 0.158528 0.043791 3.620 0.000
L1.Vorarlberg 0.097343 0.038669 2.517 0.012
L1.Wien 0.071030 0.071086 0.999 0.318
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.075149 0.049647 1.514 0.130
L1.Burgenland 0.025161 0.030257 0.832 0.406
L1.Kärnten 0.053192 0.015828 3.361 0.001
L1.Niederösterreich 0.191097 0.063241 3.022 0.003
L1.Oberösterreich 0.330304 0.062353 5.297 0.000
L1.Salzburg 0.035491 0.032098 1.106 0.269
L1.Steiermark 0.008898 0.042370 0.210 0.834
L1.Tirol 0.120002 0.034188 3.510 0.000
L1.Vorarlberg 0.065921 0.030189 2.184 0.029
L1.Wien 0.096593 0.055497 1.740 0.082
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173005 0.059850 2.891 0.004
L1.Burgenland 0.005218 0.036475 0.143 0.886
L1.Kärnten -0.065918 0.019081 -3.455 0.001
L1.Niederösterreich -0.106413 0.076238 -1.396 0.163
L1.Oberösterreich 0.205830 0.075167 2.738 0.006
L1.Salzburg 0.054874 0.038695 1.418 0.156
L1.Steiermark 0.247390 0.051077 4.843 0.000
L1.Tirol 0.501990 0.041214 12.180 0.000
L1.Vorarlberg 0.064260 0.036394 1.766 0.077
L1.Wien -0.077477 0.066903 -1.158 0.247
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160218 0.066395 2.413 0.016
L1.Burgenland -0.001454 0.040464 -0.036 0.971
L1.Kärnten 0.062748 0.021168 2.964 0.003
L1.Niederösterreich 0.167662 0.084576 1.982 0.047
L1.Oberösterreich -0.057070 0.083388 -0.684 0.494
L1.Salzburg 0.208470 0.042926 4.856 0.000
L1.Steiermark 0.139306 0.056663 2.458 0.014
L1.Tirol 0.057132 0.045722 1.250 0.211
L1.Vorarlberg 0.146927 0.040374 3.639 0.000
L1.Wien 0.119034 0.074220 1.604 0.109
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.390054 0.039084 9.980 0.000
L1.Burgenland -0.003780 0.023820 -0.159 0.874
L1.Kärnten -0.020880 0.012461 -1.676 0.094
L1.Niederösterreich 0.202203 0.049787 4.061 0.000
L1.Oberösterreich 0.230924 0.049087 4.704 0.000
L1.Salzburg 0.036733 0.025269 1.454 0.146
L1.Steiermark -0.015830 0.033355 -0.475 0.635
L1.Tirol 0.089049 0.026915 3.309 0.001
L1.Vorarlberg 0.051000 0.023766 2.146 0.032
L1.Wien 0.043536 0.043690 0.996 0.319
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036472 0.104436 0.169767 0.137876 0.098051 0.079875 0.032678 0.208287
Kärnten 0.036472 1.000000 -0.026627 0.130906 0.048860 0.084881 0.443781 -0.066893 0.089380
Niederösterreich 0.104436 -0.026627 1.000000 0.312684 0.119470 0.273223 0.067201 0.153713 0.292680
Oberösterreich 0.169767 0.130906 0.312684 1.000000 0.212733 0.295670 0.166243 0.136780 0.238336
Salzburg 0.137876 0.048860 0.119470 0.212733 1.000000 0.123083 0.092369 0.105021 0.124147
Steiermark 0.098051 0.084881 0.273223 0.295670 0.123083 1.000000 0.134304 0.107234 0.035718
Tirol 0.079875 0.443781 0.067201 0.166243 0.092369 0.134304 1.000000 0.064219 0.150508
Vorarlberg 0.032678 -0.066893 0.153713 0.136780 0.105021 0.107234 0.064219 1.000000 -0.004247
Wien 0.208287 0.089380 0.292680 0.238336 0.124147 0.035718 0.150508 -0.004247 1.000000